/**
 * 
 */
package com.jeecms.wicool.dao.shops.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.shops.ScoreShareSetDao;
import com.jeecms.wicool.entity.shops.ScoreShareSet;

/**
 * @author spring
 *
 */
@Repository
public class ScoreShareSetDaoImpl extends
		HibernateBaseDao<ScoreShareSet, Integer> implements ScoreShareSetDao {

	@Override
	public Pagination getPage(int pageNo, int pageSize, CmsUser user) {
		Finder f = Finder.create("select bean from ScoreShareSet bean where 1=1 ");
		if(user.getShopId()!=null){
			f.append(" and bean.shop.id = :shopId");
			f.setParam("shopId",user.getShopId());
		}
		f.append(" order by bean.scoreValue desc");
		return find(f, pageNo, pageSize);
	}

	@Override
	public ScoreShareSet findById(Integer id) {
		return get(id);
	}


	@Override
	public ScoreShareSet save(ScoreShareSet bean) {
		getSession().save(bean);
		return bean ;
	}

	@Override
	public ScoreShareSet deleteById(Integer id) {
		ScoreShareSet obj = get(id);
		if(obj != null){
			getSession().delete(obj);
		}
		return obj;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ScoreShareSet> getAll(CmsUser user) {
		Finder f = Finder
				.create("select bean from ScoreShareSet bean where 1 = 1 ");
		if(user.getShopId()!=null){
			f.append(" and bean.shop.id = :shopId");
			f.setParam("shopId",user.getShopId());
		}
		f.append(" order by bean.scoreValue desc");
		return find(f);
	}

	@Override
	protected Class<ScoreShareSet> getEntityClass() {
		return ScoreShareSet.class;
	}

}
